//
//  ClassListVC.m
//  XTeng
//
//  Created by 周成龙 on 16/8/17.
//  Copyright © 2016年 ZCL. All rights reserved.
//

#import "ClassListVC.h"

#import "VDJConstant.h"
#import "Header.h"

#import "CreateClassVC.h"

@interface ClassListVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSArray *contentArray;

@end

@implementation ClassListVC
- (UITableView *)tableView
{
    if (nil == _tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = kClearClolor;
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorColor = kLineColor;
        _tableView.separatorInset = UIEdgeInsetsMake(0,kMargin, 0, 0);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleLabel.text = @"班级列表";
    
    self.contentArray = @[@"高中1班", @"高中2班",  @"高中3班",  @"高中4班",  @"高中5班",  @"高中6班",  @"高中7班"];
    
    [self.view addSubview:self.tableView];
    self.tableView.sd_layout.spaceToSuperView(UIEdgeInsetsMake([self getStartOriginY], 0, 0, 0));
    
    [self initCreatButton];
}

- (void)initCreatButton
{
    
    UIView *view = [UIView new];
    view.backgroundColor = kClearClolor;
    self.tableView.tableFooterView = view;
    view.sd_layout
    .leftSpaceToView(self.tableView, 0)
    .rightSpaceToView(self.tableView, 0)
    .topSpaceToView(self.tableView, 0)
    .heightIs(50);
    
    UIButton *btn = [UIButton new];
    [btn setBackgroundImage:[UIImage imageNamed:@"按钮长"] forState:UIControlStateNormal];
    [btn setTitle:@"创建班级" forState:UIControlStateNormal];
    btn.titleLabel.font = kFontWithSize(14);
    [btn addTarget:self action:@selector(creatButton) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    btn.sd_layout
    .leftSpaceToView(view, kMargin)
    .rightSpaceToView(view, kMargin)
    .topSpaceToView(view, 10)
    .heightIs(35);
}

- (void)creatButton
{
    MyLog(@"creatButton---");
    
    CreateClassVC *vc = [[CreateClassVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.contentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    
    cell.imageView.image = [self setupCellImageViewSize:CGSizeMake(35, 35) image:[UIImage imageNamed:@"个人中心_06"]];
    cell.textLabel.text = self.contentArray[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (UIImage *)setupCellImageViewSize:(CGSize)size image:(UIImage *)image
{
    CGSize itemSize = size;
    UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0);
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
    [image drawInRect:imageRect];
    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0001f;
}

@end
